﻿using UnityEngine;
using System.Collections;

public class checkPointScritp : MonoBehaviour {
	
	playerScript myPlayer;
	bool firstTimePlayerIn;
	
	// Use this for initialization
	void Start () {
		firstTimePlayerIn = true;
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	void OnTriggerEnter(Collider myCol)
	{
		if(myCol.tag == "Player")
		{
			if(firstTimePlayerIn)
				myPlayer = myCol.GetComponent<playerScript>();
			
			if(myPlayer.transform.position.y > transform.position.y)
				return;
			
			if(myPlayer.latestCheckPoint != this.transform)
			{
				myPlayer.setCheckPoint(this.transform);
			}
		}
	}
	
}
